package com.linkage.jz.bankruptcy.activity.Project.ZQUser.DetailOper;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.adapter.FullyGridLayoutManager;
import com.linkage.jz.bankruptcy.base.BaseCreateActivity;
import com.linkage.jz.bankruptcy.bean.ApplyChangerZQUserNameBean;
import com.linkage.jz.bankruptcy.bean.TaskAtta;
import com.linkage.jz.bankruptcy.bean.ZQShowCrDecInfo;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.widget.ApplyBaseReplyDialog;
import com.linkage.jz.bankruptcy.widget.CommonPromptDialog;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.seapeak.pojo.UploadImage;
import com.linkage.seapeak.utils.CommonUtils;
import com.linkage.seapeak.utils.ToastUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


/**
 * 变更债权人名称
 */
public class ShowZQApplyActivity extends BaseCreateActivity implements OnClickListener {
    private static final String TAG = ShowZQApplyActivity.class.getSimpleName();


    @Override
    public void setListener() {

    }

    @Override
    public void initTitle() {
    }

    @Override
    public void initView() {

    }

//    private TextView ;
//    private TextView ;
//    private LinearLayout fragment_zq_zq_info_tax_base_item,fragment_zq_zq_info_notax_qr_base_item;
    private TextView tax_msg3,tax_msg4,tax_msg5,tax_msg2,tax_msg6,tax_msg7;
    private TextView notax_qr_msg1,notax_qr_msg2,notax_qr_msg3,notax_qr_msg4,notax_qr_msg5,notax_qr_msg6;
    private LinearLayout ll_yxzzdesc;

    private Button top_back1;
    private TextView tv_zqfristdesc,tv_zqdesc;
    private RecyclerView  mImgRecyclerView2,mImgRecyclerView3,mImgRecyclerView4;

    private List<UploadImage> mImgList1 = new ArrayList<>();
    private GridImagesAdapter mImgAdapter1;

    private List<UploadImage> mImgList2 = new ArrayList<>();
    private GridImagesAdapter mImgAdapter2;

    private List<UploadImage> mImgList3 = new ArrayList<>();
    private GridImagesAdapter mImgAdapter3;


    private List<UploadImage> mImgList4 = new ArrayList<>();
    private GridImagesAdapter mImgAdapter4;

    private static ZQShowCrDecInfo mInfo;


    public static void start(Context context, ZQShowCrDecInfo info) {
        Intent intent = new Intent(context, ShowZQApplyActivity.class);
        mInfo = info;
        context.startActivity(intent);
    }

    TextView top_mune1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_show_zq_apply);
        super.onCreate(savedInstanceState);
        top_mune1 = findViewById(R.id.top_mune1);
        top_mune1.setVisibility(View.INVISIBLE);
        titlebar_title = findViewById(R.id.top_title);
            titlebar_title.setText("申报信息");
        top_back1 = findViewById(R.id.top_back1);
        top_back1.setOnClickListener(this);

        initViews();
        initData();


    }


    private void initViews() {
        titlebar_back = findViewById(R.id.top_back1);

//        fragment_zq_zq_info_tax_base_item = findViewById(R.id.fragment_zq_zq_info_tax_base_item);
//        fragment_zq_zq_info_notax_qr_base_item = findViewById(R.id.fragment_zq_zq_info_notax_qr_base_item);
        tax_msg2 = findViewById(R.id.tax_msg2);
        tax_msg3 = findViewById(R.id.tax_msg3);
        tax_msg4 = findViewById(R.id.tax_msg4);
        tax_msg5 = findViewById(R.id.tax_msg5);
        tax_msg6 = findViewById(R.id.tax_msg6);
        tax_msg7 = findViewById(R.id.tax_msg7);
        notax_qr_msg1 = findViewById(R.id.notax_qr_msg1);
        notax_qr_msg2 = findViewById(R.id.notax_qr_msg2);
        notax_qr_msg3 = findViewById(R.id.notax_qr_msg3);
        notax_qr_msg4 = findViewById(R.id.notax_qr_msg4);
        notax_qr_msg5 = findViewById(R.id.notax_qr_msg5);
        notax_qr_msg6 = findViewById(R.id.notax_qr_msg6);

        ll_yxzzdesc = findViewById(R.id.ll_yxzzdesc);


        if(mInfo.getCreditorInfo()!=null)
        {
            ((TextView)findViewById(R.id.tv_zqdesc)).setText( mInfo.getProjectCrDecTemp().getCreditorRightsNote());

                    ((TextView)findViewById(R.id.tv_zqdesc)).setText( mInfo.getProjectCrDecTemp().getCreditorRightsNote());
            if("".equalsIgnoreCase( mInfo.getProjectCrDecTemp().getGuaranteePriority()) && "".equalsIgnoreCase( mInfo.getProjectCrDecTemp().getOtherPriority())
                    && "".equalsIgnoreCase( mInfo.getProjectCrDecTemp().getPreferredCreditorRightsDetail()))
            {
                findViewById(R.id.ll_frist1).setVisibility(View.VISIBLE);
                findViewById(R.id.ll_frist2).setVisibility(View.GONE);
                findViewById(R.id.ll_frist3).setVisibility(View.GONE);
//                    helper.setText(R.id.tv_frist1,"无");
                ((TextView)findViewById(R.id.tv_frist1)).setText("无");
            }else{

                findViewById(R.id.ll_frist1).setVisibility(View.VISIBLE);
                findViewById(R.id.ll_frist2).setVisibility(View.VISIBLE);
                findViewById(R.id.ll_frist3).setVisibility(View.VISIBLE);
                ((TextView)findViewById(R.id.tv_frist1)).setText(  mInfo.getProjectCrDecTemp().getGuaranteePriority());
                ((TextView)findViewById(R.id.tv_frist2)).setText( mInfo.getProjectCrDecTemp().getOtherPriority());
                ((TextView)findViewById(R.id.tv_frist3)).setText(mInfo.getProjectCrDecTemp().getPreferredCreditorRightsDetail());

            }
           if(mInfo.getCreditorInfo().getIdentityBigTypes()!=null && mInfo.getCreditorInfo().getIdentityBigTypes().getValue()==2)
            {


                    findViewById(R.id.fragment_zq_zq_info_tax_base_item).setVisibility(View.VISIBLE);
//                    float f = 0.00f;
//                    if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountRegularTax())) {
//                        f = 0.00f;
//                    } else {
//                        f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountRegularTax());
//                    }
                    tax_msg3.setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountRegularTax()) + "元");


//                    if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountOverdueFine())) {
//                        f = 0.00f;
//                    } else {
//                        f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountOverdueFine());
//                    }
                    tax_msg4.setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountOverdueFine()) + "元");

//                    if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountOther())) {
//                        f = 0.00f;
//                    } else {
//                        f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountOther());
//                    }
                    tax_msg5.setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountOther()) + "元");

//                    if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountTotal())) {
//                        f = 0.00f;
//                    } else {
//                        f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountTotal());
//                    }
                    tax_msg2.setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountTotal()) + "元");

//                    if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail())) {
//                        f = 0.00f;
//                    } else {
//                        f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail());
//                    }
                    tax_msg6.setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail()) + "元");

//                    if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail())) {
//                        f = 0.00f;
//                    } else {
//                        f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail());
//                    }
                    tax_msg7.setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail()) + "元");
//                }
                //优先主张说明
                ll_yxzzdesc.setVisibility(View.GONE);
            }
           else
               {
               ll_yxzzdesc.setVisibility(View.VISIBLE);
               if ("1".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getReviewStatus().getValue())) {
                   findViewById(R.id.fragment_zq_zq_info_notax_qr_base_item).setVisibility(View.VISIBLE);


//                   float f = 0.00f;
//                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountPrincipal())) {
//                       f = 0.00f;
//                   } else {
//                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountPrincipal());
//                   }
                   ((TextView)findViewById(R.id.notax_qr_msg1)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountPrincipal()) + "元");

//                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountInterest())) {
//                       f = 0.00f;
//                   } else {
//                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountInterest());
//                   }
                   ((TextView)findViewById(R.id.notax_qr_msg2)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountInterest()) + "元");

//                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountOther())) {
//                       f = 0.00f;
//                   } else {
//                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountOther());
//                   }
                   ((TextView)findViewById(R.id.notax_qr_msg3)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountOther()) + "元");
//
//                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountTotal())) {
//                       f = 0.00f;
//                   } else {
//                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountTotal());
//                   }
                   ((TextView)findViewById(R.id.notax_qr_msg4)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountTotal()) + "元");


                   ((TextView)findViewById(R.id.notax_qr_msg5)).setText(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail());
                   ((TextView)findViewById(R.id.notax_qr_msg6)).setText(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail());

               }else{
                   findViewById(R.id.fragment_zq_zq_info_notax_base_item).setVisibility(View.VISIBLE);

                   float f = 0.00f;
                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountPrincipal())) {
                       f = 0.00f;
                   } else {
                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountPrincipal());
                   }
                   ((TextView)findViewById(R.id.notax_msg3)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountPrincipal()) + "元");

                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountInterest())) {
                       f = 0.00f;
                   } else {
                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountInterest());
                   }
                   ((TextView)findViewById(R.id.notax_msg4)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountInterest()) + "元");

                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountOther())) {
                       f = 0.00f;
                   } else {
                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountOther());
                   }
                   ((TextView)findViewById(R.id.notax_msg5)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountOther()) + "元");

                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountTotal())) {
                       f = 0.00f;
                   } else {
                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountTotal());
                   }
                   ((TextView)findViewById(R.id.notax_msg2)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountTotal()) + "元");

                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail())) {
                       f = 0.00f;
                   } else {
                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail());
                   }
                   ((TextView)findViewById(R.id.notax_msg6)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountInterestDetail()) + "元");

                   if ("".equalsIgnoreCase(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail())) {
                       f = 0.00f;
                   } else {
                       f = Float.parseFloat(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail());
                   }
                   ((TextView)findViewById(R.id.notax_msg7)).setText(CommonUtils.resetMoney(mInfo.getProjectCrDecTemp().getDeclareAmountOtherDetail()) + "元");

               }


           }
        }




        FullyGridLayoutManager manager2 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView2 = findViewById(R.id.recycler2);
        manager2 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView2.setLayoutManager(manager2);
        mImgAdapter2 = new GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter2.setList(mImgList2);
        mImgRecyclerView2.setAdapter(mImgAdapter2);
        mImgAdapter2.setEnable(false);

        FullyGridLayoutManager manager3 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView3 = findViewById(R.id.recycler3);
        manager3 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView3.setLayoutManager(manager3);
        mImgAdapter3 = new GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter3.setList(mImgList3);
        mImgRecyclerView3.setAdapter(mImgAdapter3);
        mImgAdapter3.setEnable(false);

        FullyGridLayoutManager manager4 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView4 = findViewById(R.id.recycler4);
        manager4 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView4.setLayoutManager(manager4);
        mImgAdapter4 = new GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter4.setList(mImgList4);
        mImgRecyclerView4.setAdapter(mImgAdapter4);
        mImgAdapter4.setEnable(false);



        if(mInfo.getProjectCrDecTemp().getJudgmentAtta()!=null) {
            for (int i = 0; i < mInfo.getProjectCrDecTemp().getJudgmentAtta().size(); i++) {
                TaskAtta atta = mInfo.getProjectCrDecTemp().getJudgmentAtta().get(i);
                JSONObject obj = new JSONObject();
                try {
                    obj.putOpt("filename", atta.getAttachmentName());
                    obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                    obj.putOpt("filesize", atta.getAttachmentSize());
                    obj.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                    mImgList2.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        if(mInfo.getProjectCrDecTemp().getExecutionAtta()!=null) {
            for (int i = 0; i < mInfo.getProjectCrDecTemp().getExecutionAtta().size(); i++) {
                TaskAtta atta = mInfo.getProjectCrDecTemp().getExecutionAtta().get(i);
                JSONObject obj = new JSONObject();
                try {
                    obj.putOpt("filename", atta.getAttachmentName());
                    obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                    obj.putOpt("filesize", atta.getAttachmentSize());
                    obj.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                    mImgList3.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        if(mInfo.getProjectCrDecTemp().getOtherAtta()!=null) {
            for (int i = 0; i < mInfo.getProjectCrDecTemp().getOtherAtta().size(); i++) {
                TaskAtta atta = mInfo.getProjectCrDecTemp().getOtherAtta().get(i);
                JSONObject obj = new JSONObject();
                try {
                    obj.putOpt("filename", atta.getAttachmentName());
                    obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                    obj.putOpt("filesize", atta.getAttachmentSize());
                    obj.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                    mImgList4.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }


    }

    @Override
    public void initData() {


    }

    private boolean showflag = true;

    @Override
    public void onBackPressed() {
        finish();

    }


    private PublicNoticeDialog noticeDialog;

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {

            case R.id.titlebar_menu_text:
//                saveData();
                break;
            case R.id.top_back1:
                finish();
                break;
            default:
                break;
        }
    }





}

